import re
from xml2excel_2 import XmlGenerator
class TableRow:
    def __init__(self, key,en):
        self.key = key
        self.en = en
class CompareNewOldStringFile:
    def __init__(self, oldStringFileAbsPath, newStringFileAbsPath):
        self.oldStringFileAbsPath = oldStringFileAbsPath
        self.newStringFileAbsPath = newStringFileAbsPath

    def doCompare(self, missList ) :
        oldFile = open (self.oldStringFileAbsPath,'r')
        newFile = open (self.newStringFileAbsPath, 'r')
        oldFileContent = oldFile.read()
        newFileContent = newFile.read()
        oldFile .close()
        newFile .close()

        string_regex = re.compile(r'<string\s+name\s*=\s*"([^"]+)"\s*>([\s\S]+?)</\s*string\s*>')
        oldList =string_regex.findall(oldFileContent)
        newList =string_regex.findall(newFileContent)
        for oldItem in oldList:
            found =False
            for newItem in newList:
                if oldItem [0]== newItem[0]:
                    found =True
                    break
            if not found:
                missList.append(TableRow(oldItem[0], oldItem[1]))
if __name__ == '__main__':
    handler = CompareNewOldStringFile("/Users/h/AndroidStudioProjects/patpat/Patpat/src/main/res/values/strings.xml",
                                      "/Users/h/AndroidStudioProjects/patpat/Patpat/src/main/res/values-pl/strings.xml")
    missList =[]
    handler.doCompare(missList)
    g  = XmlGenerator()
    g.reset_row_index()

    for item in missList:
        g.write(item.key, item.en, "")
    g.done()
